package com.zhilingshenghuo.app.zhly.view.widget;

import android.app.Activity;
import android.view.Gravity;
import android.view.View;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.zhilingshenghuo.app.zhly.R;
import com.zhilingshenghuo.app.zhly.entity.RobRecordResponse;
import com.zhilingshenghuo.app.zhly.entity.SendRecordResponse;
import com.zhilingshenghuo.app.zhly.view.adapter.RobRecordAdapter;
import com.zhilingshenghuo.app.zhly.view.adapter.SendRecordAdapter;

import java.util.ArrayList;

public abstract class GameRecordPopWindow {

    private PopupWindow popupWindow;
    private Activity context;
    private ArrayList<SendRecordResponse.ListBean.DataBean> sendList;
    private ArrayList<RobRecordResponse.ListBean.DataBean> robList;

    /**
     * 构造函数
     *
     * @param context
     */
    public GameRecordPopWindow(Activity context, ArrayList<SendRecordResponse.ListBean.DataBean> sendList, ArrayList<RobRecordResponse.ListBean.DataBean> robList) {
        this.context = context;
        this.sendList = sendList;
        this.robList = robList;
    }

    /**
     * 显示警示框
     */
    public void show() {
        View popView = View.inflate(context, R.layout.pop_game_record, null);
        popupWindow = new PopupWindow(context);
        popupWindow.setAnimationStyle(R.style.popWindow_animation);//设置动画
        popupWindow.setOutsideTouchable(false);
        popupWindow.setBackgroundDrawable(null);
        int width = context.getWindowManager().getDefaultDisplay().getWidth();
        popupWindow.setWidth(width);
        int height = context.getWindowManager().getDefaultDisplay().getHeight();
        popupWindow.setHeight(height * 3 / 5);
        popupWindow.setFocusable(true);
        popupWindow.setContentView(popView);
        popupWindow.showAtLocation(context.getWindow().getDecorView(), Gravity.BOTTOM, 0, 0);
        //关闭
        popView.findViewById(R.id.ivClose).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
            }
        });

        popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                onDisMiss();
            }
        });

        RelativeLayout rlLeft = popView.findViewById(R.id.rlLeft);
        RelativeLayout rlRight = popView.findViewById(R.id.rlRight);

        RecyclerView recyclerView = popView.findViewById(R.id.recyclerView);
        SendRecordAdapter sendAdapter = new SendRecordAdapter();
        sendAdapter.setNewInstance(sendList);
        recyclerView.setAdapter(sendAdapter);
        recyclerView.setLayoutManager(new LinearLayoutManager(context, RecyclerView.VERTICAL, false));

        RobRecordAdapter robAdapter = new RobRecordAdapter();
        robAdapter.setNewInstance(robList);
        recyclerView.setLayoutManager(new LinearLayoutManager(context, RecyclerView.VERTICAL, false));


        rlLeft.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                rlLeft.setBackgroundResource(R.drawable.shape_bg_game_record_top_select);
                rlRight.setBackgroundResource(R.drawable.shape_bg_game_record_top);

                recyclerView.setAdapter(sendAdapter);
            }
        });

        rlRight.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                rlRight.setBackgroundResource(R.drawable.shape_bg_game_record_top_select);
                rlLeft.setBackgroundResource(R.drawable.shape_bg_game_record_top);

                recyclerView.setAdapter(robAdapter);
            }
        });

    }


    /**
     * 消失
     */
    public abstract void onDisMiss();
}
